﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace 递归输出文件名
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Getdir(@"D:\");
            Console.WriteLine("完成");
        }

        private static void Getdir(string path)
        {
            try
            {
                string[] array = Directory.GetDirectories(path);//获取当前路径下的目录
                for (int i = 0; i < array.Length; i++)
                {
                    //将当前目录下的文件后缀为exe的存入数组

                    string[] arraydocname = Directory.GetFiles(array[i], "*.exe");
                    File.AppendAllLines(@"E:\ExeFiles.txt", arraydocname);//向目标文件追加行
                    Getdir(array[i]);//递归
                }
            }
            catch (Exception)
            {
            }
        }
    }
}